package MyBlog.action;

import java.util.Map;

import javax.persistence.Access;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import MyBlog.biz.UserBiz;
import MyBlog.entity.User;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Scope("prototype")
@Component("userAction")
public class UserAction extends ActionSupport {

	//	实现类
	@Autowired
	private UserBiz userBiz;
	
	// 参数
	private String username;
	private String password;
	private User user;
	private Map<String,Object> sess = ActionContext.getContext().getSession();
	public void setUsername(String username) {
		this.username = username;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	
//	方法
	public String login(){
		User user = userBiz.checkLogin(username, password);
		if(user == null){
			sess.put("msg", "用户名或者密码错误");
		}else{
			sess.put("msg", null);
		}
		sess.put("user", user);
		return SUCCESS;
	}

	public String logoff(){
		sess.put("user", null);
		return SUCCESS;
	}
	
	public String sidebar(){
		user = (User) sess.get("user");
		return SUCCESS;
	}
	
}
